package com.leetcode.algorithm.y22.m08.w3;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 669. 修剪二叉搜索树
 * 
 * https://leetcode.cn/problems/trim-a-binary-search-tree/
 * 
 * @author jie.deng
 *
 */
class Question0669Solution01 {

	public TreeNode trimBST(TreeNode root, int low, int high) {
		if (root == null) {
			return root;
		}
		if (root.val < low) {
			return trimBST(root.right, low, high);
		} else if (root.val > high) {
			return trimBST(root.left, low, high);
		}

		root.left = trimBST(root.left, low, high);
		root.right = trimBST(root.right, low, high);
		return root;
	}
}